<template>
  <div class="app-container app-containerMoneytabel">
    <div class="filter-container">
      <el-input style="marginRight:15px;width: 200px;" size="small" @keyup.enter.native="handleFilter" placeholder="请输入身份证号"
        class="filter-item" v-model="listQuery.idCardSearchStr">
      </el-input>
      <el-input size="small" @keyup.enter.native="handleFilter" placeholder="请输入姓名" style="width: 200px;" class="filter-item"
        v-model="listQuery.userSearchStr">
      </el-input>
      <el-button size="small" class="filter-item filter-itemBut" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>
    <el-table :data="list" v-loading.body="listLoading" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column type="index" width="50" label="序号"></el-table-column>
      <el-table-column label="居民姓名名称" align="center" width="200">
        <template slot-scope="scope">
          {{scope.row.approvalUserName}}
        </template>
      </el-table-column>
      <el-table-column label="身份证号码" align="center">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" :content="scope.row.idCard" placement="top-start">
            <p>{{scope.row.idCard | idCardFun}}</p>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="业务类型" align="center">
        <template slot-scope="scope">
          {{ scope.row.approvalKey | mapLabel('approvalKey')}}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="created_at" label="创建时间" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span v-if="scope.row.createTime">{{scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}')}}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="版本号" align="center" width="80">
        <template slot-scope="scope">
          {{scope.row.serNum}}
        </template>
      </el-table-column> -->
      <el-table-column align="center" label="操作" width="250" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-permission="['temporary_index_collect']" type="primary" size="mini" @click="handleReception(scope.row)">立即受理</el-button>
          <el-button v-permission="['temporary_index_delete']" size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page"
        :page-sizes="[10,20,30, 50]" :page-size="listQuery.size" layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { queryPage, deleteTempById } from "@/api/temp";
import permission from "@/directive/permission/index.js"; // 权限判断指令
export default {
  directives: { permission },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      username: "",
      listQuery: {
        page: 1,
        size: 10,
        idCardSearchStr: null,
        userSearchStr: null,
        sort: "+id"
      }
    };
  },
  mounted: function() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      this.listLoading = true;
      queryPage(this.listQuery).then(response => {
        this.list = response.data.records;
        this.total = response.data.total;
        this.listLoading = false;
      });
      this.listLoading = false;
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.fetchData();
    },
    handleSizeChange(val) {
      this.listQuery.size = val;
      this.fetchData();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.fetchData();
    },
    handleReception(row) {
      this.$router.push({
        name: "collect",
        query: {
          tempId: row.id,
          approvalKey: row.approvalKey,
          content: row.content,
          temp: true
        }
      });
    },
    handleDelete(row) {
      const loading = this.$loading({
        lock: true,
        text: "提交中",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      setTimeout(() => {
        loading.close();
      }, 800);
      this.$confirm("删除后不可恢复, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        deleteTempById(row.id).then(() => {
        this.$notify({
          title: "成功",
          message: "删除成功",
          type: "success",
          duration: 2000
        });
        const index = this.list.indexOf(row);
        this.list.splice(index, 1);
      });
      }).catch(() => {
        this.$message({
          type: "info",
          message: "已取消"
        });
      });
    }
  }
};
</script>

<style scoped>
.filter-container {
  margin-bottom: 20px;
  overflow: hidden;
}

.pagination-container {
  margin-top: 25px;
  overflow: hidden;
  display: flex;
  justify-content: flex-end;
}

.filter-itemBut {
  margin-left: 25px;
}
</style>